package com.zhy.config;


import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.zhy.handler.MyMetaObjectHandler;
import com.zhy.inteceptor.SqlBeautyInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author 随缘而愈
 * @version 1.0
 * @description TODO
 * @date 24/1/2024 下午12:50
 */
@Configuration
public class MybatisConfiguration {

    @Bean
    @ConditionalOnProperty(name = "sql.logZhy.show", havingValue = "true", matchIfMissing = true)
    public SqlBeautyInterceptor sqlBeautyInterceptor() {
        return new SqlBeautyInterceptor();
    }

//    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor(){
//        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
//        return mybatisPlusInterceptor;
//    }


//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//        MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        //获取mybatis-plus全局配置
//        GlobalConfig globalConfig = GlobalConfigUtils.defaults();
//        //mybatis-plus全局配置设置元数据对象处理器为自己实现的那个
//        globalConfig.setMetaObjectHandler(new MyMetaObjectHandler());
//        mybatisSqlSessionFactoryBean.setDataSource(dataSource);
//        //mybatisSqlSessionFactoryBean关联设置全局配置
//        mybatisSqlSessionFactoryBean.setGlobalConfig(globalConfig);
//        return mybatisSqlSessionFactoryBean.getObject();
//    }


}
